package com.example.demo.controller;

import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
import com.example.demo.annotate.NoPackageResult;
import com.example.demo.common.Result;
import com.example.demo.common.ResultData;
import com.example.demo.entity.Role;
import com.example.demo.entity.UserListVO;
import com.example.demo.entity.UserVO;
import com.example.demo.entity.vo.CompanyListVO;
import com.example.demo.mapper.RoleMapper;
import com.example.demo.mapper.UserMapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/return")
@Api(tags = "0、返回值管理")
@ApiSupport(author = "罗海林", order = 0)
@Validated
@RequiredArgsConstructor
public class ReturnController {
    private final UserMapper userMapper;
    private final RoleMapper roleMapper;

    @PostMapping("/return1")
    @ApiOperation(value = "return1", notes = "用户列表页-查询按钮-调用/api/getUserInfo", response = UserVO.class)
    @ApiOperationSupport(author = "罗海林", order = 1)
    //@JsonView(UserVO.InfoJsonView.class)
    public Result return1() {
        // @JsonView在包装返回值之后无效

        UserVO user = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("邵雅");
            setJob("产品测试员");
        }};

        Result res = new Result().ok();
        res.put("info", user);
        return res;
    }

    @PostMapping("/return2")
    @ApiOperation(value = "return2", notes = "用户列表页-查询按钮-调用/api/getUserList")
    @ApiOperationSupport(author = "罗海林", order = 2)
    public Result return2() {
        UserVO user1 = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("邵雅");
            setJob("产品测试员");
        }};
        UserVO user2 = new UserVO() {{
            setId(200);
            setName("苏艺文");
        }};

        List<UserVO> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);

        Result res = new Result().ok();
        res.put("list", list);
        return res;
    }

    @PostMapping("/return3")
    @ApiOperation(value = "return3")
    @ApiOperationSupport(author = "罗海林", order = 3)
    @NoPackageResult
    public ResultData<UserVO> return3() {
        UserVO user = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("邵雅");
            //setJob("产品测试员");
        }};

        return ResultData.ok(user);
    }

    @PostMapping("/return4")
    @ApiOperation(value = "return4")
    @ApiOperationSupport(author = "罗海林", order = 4)
    @NoPackageResult
    public ResultData<List<UserVO>> return4() {
        UserVO user1 = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("邵雅");
            setJob("产品测试员");
        }};
        UserVO user2 = new UserVO() {{
            setId(200);
            setName("苏艺文");
        }};

        List<UserVO> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);

        return ResultData.ok(list);
    }

    @PostMapping("/return5")
    @ApiOperation(value = "return5")
    @ApiOperationSupport(author = "罗海林", order = 5)
    @NoPackageResult
    public ResultData<UserListVO> return5() {
        UserVO user1 = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("邵雅");
            setJob("产品测试员");
        }};
        UserVO user2 = new UserVO() {{
            setId(200);
            setName("苏艺文");
        }};

        List<UserVO> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);

        UserListVO vo = new UserListVO();
        vo.setUserList(list);
        vo.setPageIndex(5);
        vo.setPageRows(50);
        vo.setPageNum(8);

        return ResultData.ok(vo);
    }

    @PostMapping("/return6")
    @ApiOperation(value = "return6", notes = "（指明哪个页面-按钮的事件）")
    @ApiOperationSupport(author = "罗海林", order = 6)
    @NoPackageResult
    public ResultData<CompanyListVO> return6() {
        UserVO user1 = new UserVO() {{
            setId(100);
            setUserid("0507100229");
            setName("北海骄龙网络科技有限责任公司");
            setJob("JAVA高级工程师");
        }};
        UserVO user2 = new UserVO() {{
            setName("北海365");
            setJob("产品经理");
        }};

        List<UserVO> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);

        CompanyListVO vo = new CompanyListVO();
        vo.setList(list);
        vo.setPageNumber(5);
        vo.setPageSize(50);
        vo.setPageTotal(8);
        vo.setAllRecords(1066);

        return ResultData.ok(vo);
    }

    @PostMapping("/return7")
    @ApiOperation(value = "return7", notes = "（指明哪个页面-按钮的事件）")
    @ApiOperationSupport(author = "罗海林", order = 7)
    public Result return7(@RequestParam String content) {
        Result res = new Result().ok();

        if (SqlInjectionUtils.check(content)) {
            res.put("flag", true);
        }
        else {
            res.put("flag", false);
        }

        return res;
    }

    @PostMapping("/return8")
    @ApiOperation(value = "return8", notes = "（指明哪个页面-按钮的事件）")
    @ApiOperationSupport(author = "罗海林", order = 8)
    public Result return8(@RequestParam String content) {
        Result res = new Result().ok();
        res.put("content", SqlInjectionUtils.removeEscapeCharacter(content));
        return res;
    }

    @PostMapping("/return9")
    @ApiOperation(value = "return9", notes = "（指明哪个页面-按钮的事件）")
    @ApiOperationSupport(author = "罗海林", order = 9)
    @NoPackageResult
    public ResultData<Role> return9() {
        //UserRoleVO vo = userMapper.getUserRoleInfo(id);
        //Map<String, Object> vo = userMapper.getUser(id);

        //Role vo = roleMapper.getRole1("543982146luohailin");
        Role vo = roleMapper.selectById(1);



        /*LambdaQueryWrapper<Role> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Role::getId, 1);*/

        //Role vo = roleMapper.selectOne(wrapper);

        //List<Role> vo = roleMapper.selectList(wrapper);


        return ResultData.ok(vo);
    }

}
